#!/bin/bash

source $DRAW_INI
source $DRAW_CFG

mkdir -p $STAT_DIR

#optional $3 ($TARGET), i.e. whole genome if -z 
if [ -z $3 ];then
  LTAG=""
else
  LTAG="-L $3"
fi

java -Xmx5g -verbose:sizes -jar $GATK \
   -R $REF_FASTA \
   -T DepthOfCoverage \
   -I $2 \
   -l INFO \
   -omitBaseOutput \
   -omitIntervals \
   --summaryCoverageThreshold 10 \
   --summaryCoverageThreshold 20 \
   -nt $GATK_THREADS \
   $LTAG \
   -o $1 

EXITSTATUS=$?

if [ ! -e "$1.sample_statistics" ]
then
 echo "Missing output: $1"
 exit 100
fi

exit $EXITSTATUS

